package com.qf.blog.controller;

import com.qf.blog.listener.ThymeleafListener;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.WebContext;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/static/static/discuss-publish.html")
public class PublishServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        ServletContext servletContext = req.getServletContext();
        TemplateEngine templateEngine = ThymeleafListener.getTemplateEngine(servletContext);

        // 它是thymeleaf中域对象,解析时需要的数据可以放到这个对象里面
        WebContext webContext = new WebContext(req, resp, servletContext);
        templateEngine.process("view/site/discuss-publish", webContext, resp.getWriter());
    }
}
